package com.wanshi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanshi.entity.Cust;
import com.wanshi.mapper.CustMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustService {

    @Autowired
    private CustMapper mapper;

    //查询所有
    public List<Cust> list(){
        return mapper.list();
    }

    //添加客户
    public void addUser(Cust cust){
        mapper.addUser(cust);
    }

    //模糊查询
    public List<Cust> findByCond(Cust cust){
        return mapper.findByCond(cust);
    }


    //分页显示
    public PageInfo pageByCond(int page,int size,Cust cust){

        PageHelper.startPage(page,size);
        List<Cust> list = mapper.findByCond(cust);
        PageInfo<Cust> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    //删除
    public int delUser(int id){
        return mapper.delUser(id);
    }

    //批量删除
    public void delBatch(String[] ids){
        mapper.delBatch(ids);
    }


    //根据id获取用户
    public Cust findUserById(int id){
        return mapper.findUserById(id);
    }

    //修改
    public void update(Cust cust){
        mapper.update(cust);
    }


    public void updateBatch(List<Cust> list) {
        for (Cust cust : list) {
            mapper.updateBatch(cust);
        }

    }
}
